/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = t_ora_NVPair_parser.c                              */
/*  NOTE      =                                                    */
/*  DATE      = 2016/03/16 by jikw                                 */
/*******************************************************************/

#include <CUnit/Basic.h>
#include <stdlib.h>

#include "frcomm.h"
#include "frmem.h"

#include "../../../../src/module/oracle/config.h"
#include <oracle/ora_core.h>
#include <oracle/comm/ora_comm.h>

static int __suite_init(void)
{
    return 0;
}

static int __suite_cleanup(void)
{
    return 0;
}

int ora_NVPair_parser(char *p_data, unsigned int ui_len, Frlist_header *p_st_head, Frstr *p_ancestor_keys);
void ora_NVPair_list_node_free(Frlist_node *p_st_node);

static void __case1(void)
{
    int i_ret = 0;
    int ui_len = 0;
    char *p_data = NULL;
    Frlist_header *p_st_head = NULL;
    Frstr *p_ancestor_keys = NULL;

    i_ret = ora_NVPair_parser(p_data, ui_len, p_st_head, p_ancestor_keys);

    CU_ASSERT_EQUAL(i_ret, FR_FAIL);
}

//注释掉p_st_node = frlist_node_create(p_st_NVPair);
static void __case2(void)
{
    int i_ret = 0;
    int ui_len = 16;
    char *p_data = NULL;
    Frlist_header *p_st_head = NULL;
    Frstr *p_ancestor_keys = NULL;

    p_data = (char *)frmalloc(ui_len+1);
    snprintf(p_data, ui_len+1, "%s", "DESCRIPTION=test");

    i_ret = ora_NVPair_parser(p_data, ui_len, p_st_head, p_ancestor_keys);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);

    frfree(p_data);
    frfree(p_st_head);
}

static void __case3(void)
{
    int i_ret = 0;
    int ui_len = 128;
    char *p_data = NULL;
    Frlist_header *p_st_head = NULL;
    Frstr *p_ancestor_keys = NULL;

    p_data = (char *)frmalloc(ui_len+1);
    snprintf(p_data, ui_len+1, "%s", "DESCRIPTION=(CONNECT_DATA=(SID=orcl)(CID=(PROGRAM=)(HOST=__jdbc__)(USER=)))(ADDRESS=(PROTOCOL=tcp)(HOST=172.16.0.74)(PORT=1521))");

    i_ret = ora_NVPair_parser(p_data, ui_len, p_st_head, p_ancestor_keys);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);

    frfree(p_data);
    frfree(p_st_head);
}

int add_suite_ora_NVPair_parser(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" ora_NVPair_parser()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    if (CU_add_test(pSuite, "case1", __case1) == NULL ||
        CU_add_test(pSuite, "case2", __case2) == NULL ||
        CU_add_test(pSuite, "case3", __case3) == NULL)
        return FR_FAIL;

    return FR_SUCC;
}
